package logic

import (
	"context"
	"doctor-medicine-system/model/mysql"
	"doctor-medicine-system/usersrpc/internal/svc"
	"doctor-medicine-system/usersrpc/usersrpc"
	"errors"

	"github.com/zeromicro/go-zero/core/logx"
)

type DoctorLoginLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDoctorLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DoctorLoginLogic {
	return &DoctorLoginLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DoctorLoginLogic) DoctorLogin(in *usersrpc.DoctorLoginRequest) (*usersrpc.DoctorLoginResponse, error) {
	// todo: add your logic here and delete this line
	var doctor mysql.Doctor
	err := doctor.FindDocByCode(mysql.DB, in.DoctorCode)
	if err != nil {
		return nil, errors.New("账号不存在")
	}
	if doctor.DoctorPassword != in.DoctorPassword {
		return nil, errors.New("密码不正确")
	}

	return &usersrpc.DoctorLoginResponse{
		DocId: int64(doctor.ID),
	}, nil
}
